<?php
class support extends database{
// add ------
	public function Add($name, $type, $account, $status, $sort){				
		if(!$this->isText($name)){
			return 3;
		}else if(!$this->isInt($type)){
			return 4;
		}else if(!$this->isText($account)){
			return 5;
		}else if(!$this->isInt($status)){
			return 6;
		}else if(!$this->isInt($sort)){
			return 7;
		}else{			
			$sql="insert into support(name, type, account, status, sort) values('".$name."', ".$type.", '".$account."', ".$status.", ".$sort.")";		
			if($result=$this->query($sql)){
				return 1;
			}else{
				return 0;
			}
			return -1;
		}
	}
// edit ------
	public function Edit($id, $name, $type, $account, $status, $sort){				
		if(!$this->isInt($id)){
			return 2;
		}else if(!$this->isText($name)){
			return 3;
		}else if(!$this->isInt($type)){
			return 4;
		}else if(!$this->isText($account)){
			return 5;
		}else if(!$this->isInt($status)){
			return 6;
		}else{			
			$sql="update support set name='".$name."', type=".$type.", account='".$account."', status=".$status.", sort=".$sort." where id=".$id."";		
			if($result=$this->query($sql)){
				return 1;
			}else{
				return 0;
			}
			return -1;
		}
	}
	// Del ------
	public function Del($id){				
		if(!$this->isInt($id)){
			return 2;
		}else{			
			$sql="delete from support where id=".$id."";		
			if($result=$this->query($sql)){
				return 1;
			}else{
				return 0;
			}
		}
	}
// get by id
	public function GetById($id){	
		if(!$this->isInt($id)){
			return 2;
		}else{	
			$sql="select id, name, type, account, status, sort from support where id=".$id."";
			if($result=$this->query($sql)){
				if($this->CountRow($result)>0){
					while(($a=$this->fetch($result))!=NULL){
						$ds_sp[]=$this->unvalid($a); 
					}
					return $ds_sp;		
				}else{
					return 1;
				}
			}
		}
		return 0;
	}
// get all
	public function GetByAll($status=10){	
		if(!$this->isInt($status)){
			return 2;
		}else{	
			if($status==10){
				$status	= "status<>2";	
			}else{
				$status	= " status=".$status;	
			}
			$sql="select id, name, type, account, status, sort from support where ".$status." order by type asc, id ";
			if($result=$this->query($sql)){
				if($this->CountRow($result)>0){
					while(($a=$this->fetch($result))!=NULL){
						$ds_sp[]=$this->unvalid($a); 
					}
					return $ds_sp;		
				}else{
					return 1;
				}
			}
		}
		return 0;
	}
// get type
	public function GetByType($type, $status=10){	
		if(!$this->isInt($type)){
			return 2;
		}else if(!$this->isInt($status)){
			return 3;
		}else{	
			if($status==10){
				$status	= "status<>2";	
			}else{
				$status	= " status=".$status;	
			}
			$sql="select id, name, type, account, status, sort from support where type=".$type." and ".$status." order by id ";
			if($result=$this->query($sql)){
				if($this->CountRow($result)>0){
					while(($a=$this->fetch($result))!=NULL){
						$ds_sp[]=$this->unvalid($a); 
					}
					return $ds_sp;		
				}else{
					return 1;
				}
			}
		}
		return 0;
	}
// get Max sort
	public function GetMaxSort(){			
		$sql="select max(sort) as sort from support";
		if($result=$this->query($sql)){
			$a=$this->fetch($result);
			return $a['sort'];
		}
		return 0;
	}
}
?>